<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>系统管理</title>
  <link rel="stylesheet" href="styles.css">
  	<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/engine.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/util.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/interface/AjaxUsersDAO.js"></script>
</head>
<body>
  <header>
    <h1>系统管理</h1>
    <nav>
      <ul>
        <li><a href="index.jsp">首页</a></li>
        <li><a href="getList.action">系统管理</a></li>
        <li><a href="customer-management.jsp">客户信息管理</a></li>
        <li><a href="car-management.jsp">汽车信息管理</a></li>
        <li><a href="employee-management.jsp">员工信息管理</a></li>
        <li><a href="sales-management.jsp">销售信息管理</a></li>
      </ul>
    </nav>
  </header>

  <div class="content">
    <h2>用户管理</h2>
      <div class="modal">
     	<div class="modal-content">
    	   <form id="getUsersByName" action="getUsersByName.action" method="post">
    	      <tr>
       			 <td><input type="text" id="userName" name="users.userName" style="width:180px;" required/></td>
       			 <td><button  type="submit">查询</button></td>	
       		 </tr>
       	  </form>
       </div>
     </div>
    <table>
      <thead>
        <tr>
          <th>用户ID</th>
          <th>用户名</th>
          <th>密码</th>
          <th>邮箱</th>
          <th>状态</th>
          <th>是否管理员</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
       <s:iterator value="#request.usersList" id="usersList">
        <tr>
          <td><s:property value="#usersList.userId" /></td>
          <td><s:property value="#usersList.userName" /></td>
          <td><s:property value="#usersList.password" /></td>
          <td><s:property value="#usersList.email" /></td>
          <td><s:property value="#usersList.status" /></td>
          <td><s:property value="#usersList.isAdmin" /></td>
          <td>
             <button onclick="openEditModal(<s:property value='#usersList.userId' />)">修改</button>
             <a href="delUser.action?users.userId=<s:property value='#usersList.userId' />"><button onclick="if(!confirm('确定删除吗？'))return false;else return true;">删除</button></a>
          </td>
        </tr>
        </s:iterator>
      </tbody>
    </table>
  </div>
  <!-- Modal for editing -->
  <div id="editModal" class="modal" style="display:none;" >
    <div class="modal-content">
      <h2>编辑用户</h2>
      <form id="editUserForm" action="updateUser.action" method="post"  onSubmit="return check(this)">
        <input type="text" id="editUserId" name="users.userId" />
        <label for="editUserName">用户名:</label><br>
        <input type="text" id="editUserName" name="users.userName" required/><br><br>
        <label for="editPassword">密码:</label><br>
        <input type="password" id="editPassword" name="users.password" required/><br><br>
        <label for="editEmail">邮箱:</label><br>
        <input type="email" id="editEmail" name="users.email" required/><br><br>
        <label for="editStatus">状态:</label><br>
        <input type="text" id="editStatus" name="users.status" required/><br><br>
        <label for="editIsAdmin"  name="users.isAdmin">是否管理员:</label><br>
        <select id="editIsAdmin" name="users.isAdmin" >
          <option value="true">是</option>
          <option value="false">否</option>
        </select><br><br>
        <button type="submit">保存修改</button>
      </form>
    </div>
 </div>

    <script>

    function openEditModal(userId) {
	
      document.getElementById('editUserId').value = userId;
      document.getElementById('editModal').style.display = "block";
    }

    // Close the modal
    function closeEditModal() {
      document.getElementById('editModal').style.display = "none";
    }
    




  </script>
</body>
</html>
